﻿var flage = 0;
$(".upbtn").click(function (e) {
    showUpAlert(e)
    var zid = $(this).attr("id");
    zid = zid.substring(2, zid.length);
    alert("zid1=" + zid);
    alert("flage1=" + flage);
    $("#upn" + zid).load("/Note_comment/ajax_updown.aspx?flage=0&ID=" + zid);
});

$(".downbtn").click(function (e) {
    showUpAlert(e)
    var zid = $(this).attr("id");
    var xxx = flage;
    if (zid.substring(0, 4) == "ddwn")
        xxx = 0;
    zid = zid.substring(4, zid.length);

    alert("zid2=" + zid);
    alert("flage2=" + xxx);
    $("#downn" + zid).load("/Note_comment/ajax_updown.aspx?flage=1&ID=" + zid);

});

function showUpAlert(e, leftWidth) {
    $("#upAlertShow").show();
    var y = (e.pageY);
    var eventY = e.pageY + 40;
    var envetX = e.pageX;
    if (leftWidth) {
        envetX += leftWidth;
        y += 30;
    }
    document.getElementById("upAlertShow").style.left = envetX + "px";
    document.getElementById("upAlertShow").style.top = y + "px";
    var interval = setInterval(function () {
        y -= 20;
        document.getElementById("upAlertShow").style.top = y + "px";
        if (leftWidth) {
            if (y <= e.pageY - 20) {
                $("#upAlertShow").hide();
                clearInterval(interval);
            }
        } else {
            if (y <= e.pageY - 80) {
                $("#upAlertShow").hide();
                clearInterval(interval);
            }
        }
    }, 150);
}

function showUpAlertWithControl(id) {

    alert("a1");
    $("#upAlertShow").show();
    var point = getElementPos(id);
    //alert(point.x+"_"+point.y);
    var y = point.y;
    document.getElementById("upAlertShow").style.left = point.x + "px";
    document.getElementById("upAlertShow").style.top = point.y + "px";
    var interval = setInterval(function () {
        y -= 20;
        document.getElementById("upAlertShow").style.top = y + "px";
        if (y <= point.y - 80) {
            $("#upAlertShow").hide();
            clearInterval(interval);
        }
    }, 150);
}

function getElementPos(elementId) {

    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof   
    var el = document.getElementById(elementId);
    if (el.parentNode === null || el.style.display == 'none') {
        return false;
    }
    var parent = null;
    var pos = [];
    var box;
    if (el.getBoundingClientRect)    //IE   
    {
        box = el.getBoundingClientRect();
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        return { x: box.left + scrollLeft, y: box.top + scrollTop };
    } else if (document.getBoxObjectFor)    // gecko       
    {
        box = document.getBoxObjectFor(el);
        var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
        var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
        pos = [box.x - borderLeft, box.y - borderTop];
    } else    // safari & opera       
    {
        pos = [el.offsetLeft, el.offsetTop];
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) {
                pos[0] += parent.offsetLeft;
                pos[1] += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }
        if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) {
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }
    if (el.parentNode) {
        parent = el.parentNode;
    } else {
        parent = null;
    }
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors   
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) {
            parent = parent.parentNode;
        } else {
            parent = null;
        }
    }
    return { x: pos[0], y: pos[1] };
}


var index = 0;
var xx = 0;
$(document).ready(function () {


    $("#ddlHotM").change(function () {
        if ($(this).val() != 0) {

            alert("a2=" + $(this).val());
            window.location.href = "/Note_comment/default.html?filmid=" + $(this).val();
        }
    })

    $(".smsreplaytxt").each(function () {
        $(this).focus(function () {
            alert("a3");
            $(this).removeClass("color999");
            var txt = $(this).val();
            if (txt == '有什么想说的？发表您的看法吧！') { $(this).val(""); }
        })

        $(this).blur(function () {
            alert("a4");
            $(this).addClass("color999");
            var txt = $(this).val();
            if (txt == '') { $(this).val("有什么想说的？发表您的看法吧！"); }
        })
    });


    $(".sms-dl").hover(
	  function () {
	      $(this).children("dd").addClass("moveon");
	  },
	  function () {
	      $(this).children("dd").removeClass("moveon");
	  }
	);
    $("#replyOkBtn").click(function (e) {
        alert("a5");
        if (xx == 0) {
            xx = 1;
            $.ajax({ type: 'POST', url: '/Note_comment/NoteOperate.ashx?Operation=replynote&ID=' + index, data: 'note=' + escape($("#replyContent").val()), success: function (data) {
                var item = data.split('|');
                if (item[0] == 1) {
                    alert("您输入的内容包含非法字符！");
                    $("#replyContent").focus();
                } else {
                    showUpAlert(e, 35);
                    $("#replyCount" + index).html(item[1]);
                    $("#replyContent").val('');
                    $("#opensmsbox").fadeOut();
                    $("#opensmsiframe").fadeOut();
                }
            }
            });
        } else {
            xx = 0;
        }
    });
    $(".smsnum").each(function () {
        $(this).click(function (e) {
            alert("a6");
            index = this.id.substring(10, this.id.length);
            var off = $(this).offset();
            $("#opensmsbox").fadeIn();
            $("#opensmsiframe").fadeIn();
            $("#opensmsbox").css("left", off.left - 224);
            $("#opensmsbox").css("top", off.top - 120);
            $("#opensmsiframe").css("left", off.left - 224);
            $("#opensmsiframe").css("top", off.top - 120);
        });
    });
    $("#hidesmsbox").click(function () {
        alert("a7");
        $("#replyContent").val('');
        $(this).parents("#opensmsbox").fadeOut();
        $("#opensmsiframe").fadeOut();
    });

});


$(function () {
    var _wrap = $('#dxypwp');
    var _interval = 5000;
    var _moving;
    _wrap.hover(function () {
        clearInterval(_moving);
    }, function () {
        _moving = setInterval(function () {
            //alert("a8");
            var _field = _wrap.find('dl:first');
            var _h = _field.height();
            _field.animate({ marginTop: -_h + 'px' }, function () {
                _field.css('marginTop', 0).appendTo(_wrap);
            })
        }, _interval)
    }).trigger('mouseleave');

    var caseReplyCloud = setInterval(function () {
        //alert("a9");
        if ($('#opensmsbox').css("display") != "none") {
            clearInterval(_moving);
        }
    }, 100);
});